package com.example.demo.dto;

public class ResponseDTO<T> {
    private int code;
    private String message;
    private T data;

    public static <T> ResponseDTO<T> success(T data) {
        return success("成功", data);
    }

    // 新增带消息参数的 success 方法
    public static <T> ResponseDTO<T> success(String message, T data) {
        ResponseDTO<T> responseDTO = new ResponseDTO<>();
        responseDTO.setCode(200);
        responseDTO.setMessage(message);
        responseDTO.setData(data);
        return responseDTO;
    }

    public static <T> ResponseDTO<T> error(int code, String message) {
        ResponseDTO<T> responseDTO = new ResponseDTO<>();
        responseDTO.setCode(code);
        responseDTO.setMessage(message);
        return responseDTO;
    }

    // getter 和 setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
